const mapArray = require('map-array');

function test1 () {
	const obj = {
		giorgio: 'Bianchi',
		gino: 'Rossi'
	};
	console.log(mapArray(obj, (key, value) => key + ' ' + value));

	var arr = [3, 2, 5]
	console.log(mapArray(arr, function(key, value) {
		console.log(arguments)
		console.log(typeof key, key)
		console.log(typeof value, value)
		return key + ' ' + value
	}));


	for(var i in arr) {
		console.log(i, typeof i,  arr.hasOwnProperty(i))
	}

	/*
	console.log(mapArray(3,  function (key, value) {
		console.log(key + ' ' + value)
	}));
	*/

}


function test2() {
	const obj = {
		giorgio: 'Bianchi',
		gino: 'Rossi'
	};
	console.log(mapArray(obj, (key, value) => key + ' ' + value));
	console.log('--------------------------------------------\n')

	console.log(myMapArray(obj, function(key, value) { 
		return key + ' ' + value
	}));

}

 
test3()
function test3() {
	const obj = {FOO: true, bAr: {bAz: true}} ;
	var options = {deep: true}
	console.log(mapArray(obj, (key, value) => key + ' ' + value, options));
	console.log('--------------------------------------------\n')
	console.log(myMapArray(obj, function(key, value) {
		return key + ' ' + value
	}, options));
}






function myMapArray(obj, fn, thisArg) {

	if(typeof obj !== 'object' || obj == null) {
		return 
	}

	var arr = []
	for(var i in obj) {
		var ret = fn.call(thisArg, i, obj[i], obj)
		arr.push(ret)
	}

	return arr
}